home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / amiga / asrc29k.lha / asy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  4.8 KB  |  205 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "iface.h"
  4. #include "netuser.h"
  5. #include "amiga/asy.h"
  6. #include "ax25.h"
  7. #include "kiss.h"
  8. #include "slip.h"
  9. #include "slcompre.h"
  10. #include "ppp.h"
  11. #include "nrs.h"
  12. #include "config.h"
  13. #include "proc.h"
  14. #include "commands.h"
  15.  
  16. /* Attach a serial interface to the system
  17.  * argv[0]: hardware type, must be "asy"
  18.  * argv[1]: I/O address, e.g., "0x3f8"
  19.  * argv[2]: vector, e.g., "4"
  20.  * argv[3]: mode, may be:
  21.  *        "slip" (point-to-point SLIP)
  22.  *        "ax25" (AX.25 frame format in SLIP for raw TNC)
  23.  *        "nrs" (NET/ROM format serial protocol)
  24.  * argv[4]: interface label, e.g., "sl0"
  25.  * argv[5]: receiver ring buffer size in bytes
  26.  * argv[6]: maximum transmission unit, bytes
  27.  * argv[7]: interface speed, e.g, "9600"
  28.  * argv[8]: optional flags, e.g., 'c' for cts flow control
  29.  */
  30. int
  31. asy_attach(argc,argv,p)
  32. int argc;
  33. char *argv[];
  34. void *p;
  35. {
  36.     register struct iface *if_asy;
  37.     int dev;
  38.     int mode;
  39.     int xdev;
  40.     int trigchar = -1;
  41.     char cts;
  42.  
  43.     if(Nasy >= ASY_MAX){
  44.         tprintf("Too many asynch controllers\n");
  45.         return -1;
  46.     }
  47.     if(if_lookup(argv[4]) != NULLIF){
  48.         tprintf("Interface %s already exists\n",argv[4]);
  49.         return -1;
  50.     }
  51.     if(strcmp(argv[3],"slip") == 0)
  52.         mode = SLIP_MODE;
  53.     else if(strcmp(argv[3],"ax25") == 0)
  54.         mode = AX25_MODE;
  55.     else if(strcmp(argv[3],"nrs") == 0)
  56.         mode = NRS_MODE;
  57.     else if(strcmp(argv[3],"ppp") == 0)
  58.         mode = PPP_MODE;
  59.     else 
  60.         mode = UNKNOWN_MODE;
  61.  
  62.     dev = Nasy++;
  63.  
  64.     /* Create interface structure and fill in details */
  65.     if_asy = (struct iface *)callocw(1,sizeof(struct iface));
  66.     if_asy->addr = Ip_addr;
  67.     if_asy->name = strdup(argv[4]);
  68.     if_asy->mtu = atoi(argv[6]);
  69.     if_asy->dev = dev;
  70.     if_asy->stop = asy_stop;
  71.  
  72.     switch(mode){
  73. #ifdef    SLIP
  74.     case SLIP_MODE:
  75.         setencap(if_asy,"SLIP");
  76.         if_asy->ioctl = asy_ioctl;
  77.         if_asy->raw = slip_raw;
  78.         if_asy->flags = 0;
  79.         if(Nslip >= SLIP_MAX) {
  80.             tprintf("Too many slip devices\n");
  81.             return -1;
  82.         }
  83.         xdev = Nslip++;        
  84.         if_asy->xdev = xdev;
  85.  
  86.         Slip[xdev].iface = if_asy;
  87.         Slip[xdev].send = asy_send;
  88.         Slip[xdev].get = get_asy;
  89.         Slip[xdev].type = TYPE_SLIP;
  90.         Slip[xdev].slcomp = 0L;
  91.         trigchar = FR_END;
  92.         if_asy->proc = newproc("asy rx",512,asy_rx,xdev,NULL,NULL);
  93.         break;
  94. #endif
  95. #ifdef    AX25
  96.     case AX25_MODE:  /* Set up a SLIP link to use AX.25 */
  97.         axarp();
  98.         setencap(if_asy,"AX25");
  99.         if_asy->ioctl = kiss_ioctl;
  100.         if_asy->raw = kiss_raw;
  101.         if(if_asy->hwaddr == NULLCHAR)
  102.             if_asy->hwaddr = mallocw(AXALEN);
  103.         memcpy(if_asy->hwaddr,Mycall,AXALEN);
  104.         if(Nslip >= SLIP_MAX) {
  105.             tprintf("Too many slip devices\n");
  106.             return -1;
  107.         }
  108.         xdev = Nslip++;        
  109.         if_asy->xdev = xdev;
  110.         if_asy->port = 0;                /* G1EMM */
  111.  
  112.         Slip[xdev].iface = if_asy;
  113.         Slip[xdev].kiss[if_asy->port] = if_asy;        /* G1EMM */
  114.         Slip[xdev].send = asy_send;
  115.         Slip[xdev].get = get_asy;
  116.         Slip[xdev].type = TYPE_KISS;
  117.         trigchar = FR_END;
  118.         if_asy->proc = newproc("asy rx",256,asy_rx,xdev,NULL,NULL);
  119.         break;
  120. #endif
  121. #ifdef    NRS
  122.     case NRS_MODE: /* Set up a net/rom serial iface */
  123.         /* no call supplied? */
  124.         setencap(if_asy,"AX25");
  125.         if_asy->ioctl = asy_ioctl;
  126.         if_asy->raw = nrs_raw;
  127.         if_asy->hwaddr = mallocw(AXALEN);
  128.         memcpy(if_asy->hwaddr,Mycall,AXALEN);
  129.         if(Nnrs >= SLIP_MAX) {
  130.             tprintf("Too many nrs devices\n");
  131.             return -1;
  132.         }
  133.         xdev = Nnrs++;        
  134.         if_asy->xdev = xdev;
  135.         Nrs[xdev].iface = if_asy;
  136.         Nrs[xdev].send = asy_send;
  137.         Nrs[xdev].get = get_asy;
  138.         trigchar = ETX;
  139.         if_asy->proc = newproc("nrs rx",256,nrs_recv,xdev,NULL,NULL);
  140.         break;
  141. #endif
  142. #ifdef PPP
  143.     case PPP_MODE:    /* Setup for Point-to-Point interface */
  144.         setencap(if_asy, "PPP");
  145.         if_asy->ioctl = asy_ioctl;
  146.         if_asy->raw = ppp_raw;
  147.         if_asy->flags = 0;
  148.         if(Nslip >= SLIP_MAX) {
  149.             tprintf("Too many slip/ppp devices\n");
  150.             return -1;
  151.         }
  152.         xdev = Nslip++;        
  153.         if_asy->xdev = xdev;
  154.  
  155.         Slip[xdev].iface = if_asy;
  156.         Slip[xdev].send = asy_send;
  157.         Slip[xdev].get = get_asy;
  158.         Slip[xdev].type = TYPE_PPP;
  159.         Slip[xdev].escaped = 0;
  160.         trigchar = HDLC_FLAG;
  161.         /* Allocate PPP control structure */
  162.         Slip[xdev].pppio = (struct pppctl *)calloc(1,sizeof(struct pppctl));
  163.         if (Slip[xdev].pppio == NULLPPPCTL) {
  164.             tprintf("Cannot allocate PPP control block\n");
  165.             free(if_asy->name);
  166.             free((char *)if_asy);
  167.             Nasy--;
  168.             Nslip--;
  169.             return -1;
  170.         }
  171.         /* Initialize parameters for various PPP phases/protocols */
  172.         if (ppp_init(xdev) == -1) {
  173.             free(if_asy->name);
  174.             free((char *)if_asy);
  175.             Nasy--;
  176.             Nslip--;
  177.             return -1;
  178.         }
  179.         if_asy->proc = newproc("ppp recv", 256,    ppp_recv, xdev, NULL, NULL);
  180.         break;
  181. #endif /* PPP */
  182.     default:
  183.         tprintf("Mode %s unknown for interface %s\n",
  184.             argv[3],argv[4]);
  185.         free(if_asy->name);
  186.         free((char *)if_asy);
  187.         Nasy--;
  188.         return -1;
  189.     }
  190.     if_asy->proc1 = newproc("asy tx",256,asy_tx,dev,NULL,NULL);
  191.     if_asy->next = Ifaces;
  192.     Ifaces = if_asy;
  193.     if(argc > 8 && *argv[8] == 'c')
  194.         cts = 1;
  195.     else
  196.         cts = 0;
  197.     asy_init(dev,if_asy,argv[1],argv[2],
  198.         (unsigned)atoi(argv[5]),trigchar,
  199.         cts,atoi(argv[7]));
  200.  
  201.     asy_speed(dev,atoi(argv[7]));
  202.     return 0;
  203. }
  204.  
  205.